angular.
module('adminMain').
component('adminMain', {
  templateUrl:
  'views/app/admin-main/admin-main.template.html',
  controller: function ($scope,$cookies,$http,$window,$location,$rootScope) {

    if ($cookies.get('sessionID') == undefined){
      $window.location = '/login'
    }
        $scope.today = formatDate(new Date())


    var query = {}
    query.session = $cookies.get('sessionID')
          $http({
              method: 'post',
              url: '/admin/getAdminDashBoard',
              data : query
              
          }).success(function(datax) {
             if (datax.code == 401){
            $window.location = '/login'
            return false
          }
          else if (datax.code == 200){
            $scope.totalUser = datax.data.totalUser 
            $scope.newUser = datax.data.newUser 
            $scope.totalTestTubeUser = datax.data.totalTestTubeUser
            $scope.newTestTubeUser = datax.data.newTestTubeUser 
            $scope.totalUserChange =  ($scope.newUser)/ parseFloat(($scope.totalUser - $scope.newUser) > 0 ? ($scope.totalUser  - $scope.newUser): 1).toFixed(4) * 100 
            $scope.totalTestTubeUserChange =  ($scope.newTestTubeUser)/ parseFloat(($scope.totalTestTubeUser - $scope.newTestTubeUser) > 0 ? ($scope.totalTestTubeUser  - $scope.newTestTubeUser): 1).toFixed(4) * 100 
          }


})



      function formatDate(date){
        xdate = new Date(date)
        var year = xdate.getFullYear()
        var day = xdate.getDate()
        var month = xdate.getMonth()
        var hour = xdate.getHours()
        var minute = xdate.getMinutes()
        return String(year) + '-' + String(month+1) + '-' + String(day)
      }



      function addZeroBefore(n) {
        return (n < 10 ? '0' : '') + n;
      }

      $scope.contentChanged = function(editor, html, text, content){
        console.log(editor,html,text,content)
      }


  }})



